package com.anycc.cloud.common.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.apache.commons.lang3.time.DateFormatUtils;

import java.io.IOException;
import java.util.Date;

/**
 * 时间序列化类
 */
public class DateTimeJsonSerializer extends JsonSerializer<Date> {
    public DateTimeJsonSerializer() {

    }

    public void serialize(Date date, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        jsonGenerator.writeString(DateFormatUtils.format(date, "yyyy-MM-dd HH:mm:ss"));
    }
}
